#include "namepipe.hpp"

int main()
{
    const char* str = "pipe";
    //服务端创建有名管道
    namepipe p1(str);

    int fd = open(str,O_RDONLY);
    if(fd == -1)
    {
        perror("open");
        return 1;
    }

    char arr[1024];
    while(1)
    {
        int ret = read(fd,arr,sizeof(arr) - 1);
        if(ret > 0)
        {
            arr[ret] = 0;
        }
        else if(ret == 0)
        {
            cout << "write quit , I quit" << endl;
            break;
        }
        else
        {
            perror("read");
            return 1;
        }

        //读取成功
        sleep(1);
        cout << arr << endl;
    }
    
    close(fd);
    return 0;
}